#ifndef __LISTENER_H__
#define __LISTENER_H__

#include <poller.h>
#include <noncopyable.h>

class CPollerUnit;

HTTP_SVR_NS_BEGIN

class THttpStateInfo;
class CHttpDecoder;

class CDecoderUnit;

class CListener : public CPollerObject, private noncopyable
{
public:
	CListener (const char* addr, uint16_t port, int acceptcnt);
	virtual ~CListener (void);
    
	virtual int InputNotify(void);
	int Attach (CPollerUnit*, int);
	int FD(void) const { return netfd; }

    void complete (CDecoderUnit* decoderunit);


private: //method
    CDecoderUnit* create_decoderunit (THttpStateInfo* httpinfo);
    int proc_accept (struct sockaddr_in* peer, socklen_t* peerSize);
    int proc_request (struct sockaddr_in* peer);

private: //property
    CPollerUnit*    _pollerunit;
    CHttpDecoder*   _decoder;
    int             _accept_cnt;
    int             _newfd_cnt;
    int*            _fd_array;
    int             _accept_num;
	uint16_t        _bindPort;
	char            _bindAddr[128];
}; 

HTTP_SVR_NS_END

#endif
